package com.xuecheng.web.exceptions;


import com.xuecheng.commons.enums.ErrorCode;
import com.xuecheng.commons.model.vo.ResponseResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionAdvice {


    @ExceptionHandler(RuntimeException.class)
    public ResponseResult exception(Exception e){
        e.printStackTrace();
        ErrorCode error = ErrorCode.ERROR;
        return ResponseResult.errorResult(error);
    }

    //处理业务异常
    @ExceptionHandler(BusinessException.class)
    public ResponseResult BusinessException(BusinessException e){
        e.printStackTrace();
        ErrorCode error = e.getErrorCode();
        return ResponseResult.errorResult(error);
    }
}
